package lc20240508;

import java.util.ArrayList;
import java.util.List;
//228. 汇总区间
public class Demo1 {
    public static void main(String[] args) {
        int[] nums={0,1,2,4,5,7};
        System.out.println(summaryRanges(nums));
    }
    public static List<String> summaryRanges(int[] nums) {
        List<String> list=new ArrayList<>();
        int i=0;
        int n= nums.length;
        while (i<n){
            int low=i;
            i++;
            while (i<n&&nums[i]-1==nums[i-1]){
                i++;
            }
            int high=i-1;
            StringBuilder temp=new StringBuilder(String.valueOf(nums[low]));
            if (low<high){
                temp.append("->");
                temp.append(nums[high]);
            }
            list.add(temp.toString());
        }
        return list;
    }
}
